Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxGUI/psmap: fix close vector map properties dialog after hit OK button #3085

Merged
merged 3 commits into from
Sep 16, 2023

Conversation

tmszi
Copy link
Member

@tmszi tmszi commented Jul 14, 2023

Fixes #3084.

@tmszi tmszi added bug Something isn't working GUI wxGUI related backport to 8.3 backport to 7.8 PR needs to be backported to release branch 7.8 labels Jul 14, 2023
@tmszi tmszi added this to the 8.3.1 milestone Jul 14, 2023
@tmszi tmszi force-pushed the wxgui-psmap-fix-click-vprops-dialog-ok-btn branch from c6d2f44 to 9763ed3 Compare July 14, 2023 19:35
@tmszi tmszi removed the backport to 7.8 PR needs to be backported to release branch 7.8 label Jul 15, 2023
@tmszi tmszi requested a review from petrasovaa July 15, 2023 07:25
@tmszi tmszi modified the milestones: 8.3.1, 8.4.0 Jul 18, 2023
@cmbarton
Copy link
Contributor

Has this been merged yet? Doesn't look like it.

@petrasovaa
Copy link
Contributor

Has this been merged yet? Doesn't look like it.

Not yet. I looked at it briefly some time ago and I had some issues reproducing it. Can you confirm this PR actually fixes it?

@tmszi
Copy link
Member Author

tmszi commented Sep 13, 2023

Has this been merged yet? Doesn't look like it.

Not yet. I looked at it briefly some time ago and I had some issues reproducing it. Can you confirm this PR actually fixes it?

The bug is still reproducible following the steps in the reported issue #3084 and this PR fixes it. I carefully tested each of my PRs before creating them.

@cmbarton
Copy link
Contributor

Unfortunately, this does not fix the bug. I compiled this PR and it is still there. It behaves as if closing the vector settings dialog does not relinquish the focus, even though the window is closed.

No other windows (cartographic composer layer window, main cartographic composer window, main GUI window) are responsive as if another dialog was waiting for a response.

@petrasovaa
Copy link
Contributor

petrasovaa commented Sep 14, 2023

Sorry it took so long, but finally I got to this. @tmszi yes, I can reproduce it on Ubuntu and I agree with the fix. The problem is ShowModal is not called the standard way with this dialog (testing outcome of ShowModal and then destroying the dialog would be better, but would require larger changes).

@cmbarton since this seems to fix it for Ubuntu (and I assume @tmszi tested it on linux as well, no?), could you make sure the patch is correctly applied? But it sounds like maybe the behavior with this fix is different? It could be something Mac specific.
Maybe trying self.EndModal(wx.ID_OK) instead of self.Destroy() may make a difference?

@tmszi
Copy link
Member Author

tmszi commented Sep 14, 2023

Sorry it took so long, but finally I got to this. @tmszi yes, I can reproduce it on Ubuntu and I agree with the fix. The problem is ShowModal is not called the standard way with this dialog (testing outcome of ShowModal and then destroying the dialog would be better, but would require larger changes).

My complex debug info:

Problematic is line vector map props dialog only, especially PenStyleComboBox() widget, respectively base class OwnerDrawnComboBox widget.

self.styleCombo = PenStyleComboBox(
panel, choices=penStyles, validator=TCValidator(flag="ZERO_AND_ONE_ONLY")
)

If you try comment code lines 2927-2960, confirming line vector map props dialog Ok button widget works as expected.

Others vector map props dialog (point and area type), confirming Ok button widget works as expected. Because doesn't use PenStyleComboBox widget.

Another bug (new PR) is in PenStyleComboBox class OnDrawItem method (DrawText and DrawLine method), under wxGTK.

Traceback (most recent call last):
  File "/usr/lib64/grass84/gui/wxpython/psmap/dialogs.py", line 182, in OnDrawItem
    dc.DrawText(
TypeError: DC.DrawText(): arguments did not match any overloaded call:
  overload 1: argument 3 has unexpected type 'float'
  overload 2: argument 2 has unexpected type 'int'

dc.DrawText(
self.GetString(item),
r.x + 3,
(r.y + 0) + ((r.height / 2) - dc.GetCharHeight()) / 2,
)
dc.DrawLine(
r.x + 5,
r.y + ((r.height / 4) * 3) + 1,
r.x + r.width - 5,
r.y + ((r.height / 4) * 3) + 1,
)

@cmbarton since this seems to fix it for Ubuntu (and I assume @tmszi tested it on linux as well, no?),

I tested this PR under wxGTK and wxMSW.

@nilason
Copy link
Contributor

nilason commented Sep 14, 2023

I can confirm that the problem persists on Mac even with this present solution, using
Python 3.11.5 (main, Aug 25 2023, 13:55:04) [Clang 13.1.6 (clang-1316.0.21.2.5)]
wxPython 4.2.1 osx-cocoa (phoenix) wxWidgets 3.2.2.1

@nilason
Copy link
Contributor

nilason commented Sep 14, 2023

The vector property window, once opened cannot be closed. By simply open it, doing nothing, then close (via cancel button), only puts the window behind all other windows, but the window doesn't close nor the modal state cannot be terminated. Only solution is to force quit gui (wxPython).

@nilason
Copy link
Contributor

nilason commented Sep 14, 2023

I tried commenting out the lines 2927-2960, but it didn't do any difference.

@petrasovaa
Copy link
Contributor

Maybe trying self.EndModal(wx.ID_OK) instead of self.Destroy() may make a difference?

Could someone on Mac try using this in the OnOK method?

@nilason
Copy link
Contributor

nilason commented Sep 14, 2023

Maybe trying self.EndModal(wx.ID_OK) instead of self.Destroy() may make a difference?

Could someone on Mac try using this in the OnOK method?

I missed that suggestion, yes it seems to work! Now, only cancel remain the same (problematic).

@nilason
Copy link
Contributor

nilason commented Sep 14, 2023

Following works for me:

    def OnCancel(self, event):
        self.EndModal(wx.ID_CANCEL)

    def OnOK(self, event):
        self.update()
        event.Skip()
        self.EndModal(wx.ID_OK) 

One (rather trivial, but still) problem remains, after closing "Vector Properties" window, the "Map settings" window looses focus and is placed behind "Cartographic Composer" window.

@cmbarton
Copy link
Contributor

One (rather trivial, but still) problem remains, after closing "Vector Properties" window, the "Map settings" window looses focus and is placed behind "Cartographic Composer" window.

This problem seems to be pervasive in the custom-designed interfaces that wrap GRASS commands (e.g., the raster and vector import tools). Trivial but annoying.

In class today, I needed to show a student why they could not import a file. After selecting the file in the raster import tool, the import window disappears behind the main GRASS GUI window. They did not know this and wondered what happened.

@nilason
Copy link
Contributor

nilason commented Sep 14, 2023

One (rather trivial, but still) problem remains, after closing "Vector Properties" window, the "Map settings" window looses focus and is placed behind "Cartographic Composer" window.

This problem seems to be pervasive in the custom-designed interfaces that wrap GRASS commands (e.g., the raster and vector import tools). Trivial but annoying.

In class today, I needed to show a student why they could not import a file. After selecting the file in the raster import tool, the import window disappears behind the main GRASS GUI window. They did not know this and wondered what happened.

Yes, now with the single window mode it is particularly annoying because it is virtually impossible to see (if the main window fills the screen). I was fooled by this several times testing this PR.

@petrasovaa
Copy link
Contributor

Following works for me:

    def OnCancel(self, event):
        self.EndModal(wx.ID_CANCEL)

    def OnOK(self, event):
        self.update()
        event.Skip()
        self.EndModal(wx.ID_OK) 

I decided to slightly refactor this, the dialog is now derived from standard wx dialog, so the hack above is not needed. Testing welcome. I did have some issues with a validator, so I removed it, it's not very important anyway,

@petrasovaa
Copy link
Contributor

One (rather trivial, but still) problem remains, after closing "Vector Properties" window, the "Map settings" window looses focus and is placed behind "Cartographic Composer" window.

That looks Mac-specific, you could try calling self.Raise() after vector properties dialog is closed.

But some of these problems with single window are general, we could explore some window settings like 'wx.FRAME_FLOAT_ON_PARENT'.

@tmszi
Copy link
Member Author

tmszi commented Sep 15, 2023

Successfully tested on wxGTK, wxMSW.

@nilason
Copy link
Contributor

nilason commented Sep 15, 2023

I decided to slightly refactor this, the dialog is now derived from standard wx dialog, so the hack above is not needed. Testing welcome. I did have some issues with a validator, so I removed it, it's not very important anyway,

That works fine!

@nilason
Copy link
Contributor

nilason commented Sep 15, 2023

One (rather trivial, but still) problem remains, after closing "Vector Properties" window, the "Map settings" window looses focus and is placed behind "Cartographic Composer" window.

That looks Mac-specific, you could try calling self.Raise() after vector properties dialog is closed.

But some of these problems with single window are general, we could explore some window settings like 'wx.FRAME_FLOAT_ON_PARENT'.

I found what I believe a better solution. In VectorPanel::OnProperties() initialise the VPropertiesDialog with self.parent instead of the present self. "self" is only the Panel, but we need to have the MapDialog as parent.

@cmbarton
Copy link
Contributor

If this is committed I can test too.

@petrasovaa
Copy link
Contributor

I found what I believe a better solution. In VectorPanel::OnProperties() initialise the VPropertiesDialog with self.parent instead of the present self. "self" is only the Panel, but we need to have the MapDialog as parent.

That makes sense. I assume you tested it, does this solve the problem with hiding the dialog on Mac?

@nilason
Copy link
Contributor

nilason commented Sep 15, 2023

That makes sense. I assume you tested it, does this solve the problem with hiding the dialog on Mac?

Yes

@cmbarton
Copy link
Contributor

This solves all reported problem with the cartographic composer. Thanks to all!

Can we add the fix to the hidden window to the raster and vector import tools too? Probably some other places need it, but I don't know which right now.

@nilason
Copy link
Contributor

nilason commented Sep 15, 2023

This solves all reported problem with the cartographic composer. Thanks to all!

👍

Can we add the fix to the hidden window to the raster and vector import tools too? Probably some other places need it, but I don't know which right now.

I looked for similar problems in the import tools, but I couldn't find any. Please, take a closer look and report in an another ticket.

@cmbarton
Copy link
Contributor

cmbarton commented Sep 15, 2023 via email

@tmszi tmszi merged commit fd59e94 into OSGeo:main Sep 16, 2023
18 checks passed
tmszi added a commit to tmszi/grass that referenced this pull request Sep 16, 2023
…on (OSGeo#3085)

* make VPropertiesDialog behave like standard dialog, don't inherit from PsmapDialog

* accept suggestion about parent to prevent hiding the dialog on wxMAC

---------

Co-authored-by: Anna Petrasova <[email protected]>
tmszi added a commit to tmszi/grass that referenced this pull request Sep 16, 2023
…on (OSGeo#3085)

* make VPropertiesDialog behave like standard dialog, don't inherit from PsmapDialog

* accept suggestion about parent to prevent hiding the dialog on wxMAC

---------

Co-authored-by: Anna Petrasova <[email protected]>
@tmszi tmszi deleted the wxgui-psmap-fix-click-vprops-dialog-ok-btn branch September 16, 2023 04:22
landam pushed a commit to landam/grass that referenced this pull request Oct 25, 2023
…on (OSGeo#3085)

* make VPropertiesDialog behave like standard dialog, don't inherit from PsmapDialog

* accept suggestion about parent to prevent hiding the dialog on wxMAC

---------

Co-authored-by: Anna Petrasova <[email protected]>
neteler pushed a commit to nilason/grass that referenced this pull request Nov 7, 2023
…on (OSGeo#3085)

* make VPropertiesDialog behave like standard dialog, don't inherit from PsmapDialog

* accept suggestion about parent to prevent hiding the dialog on wxMAC

---------

Co-authored-by: Anna Petrasova <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working GUI wxGUI related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Cartographic composer locks up GUI when setting vector properties
4 participants